<template>
  <el-dialog
    :visible.sync="dialogOpen"
    :title="dialogTitle"
    :before-close="cancel"
    width="30%"
    destroy-on-close
    :close-on-click-modal="false"
  >
    <el-form ref="form" :model="formData" :rules="rules" label-width="100px">
      <el-row>
        <el-col :span="24">
          <el-form-item label="文件名" prop="fileNamePrefix">
            <el-input v-model="formData.fileNamePrefix" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="文件扩展名" prop="fileNameSuffix">
            <el-input v-model="formData.fileNameSuffix" placeholder="请输入" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="文件大小" prop="maxFileSize">
            <el-input v-model="formData.maxFileSize" placeholder="请输入" />
          </el-form-item>
        </el-col>
       
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>
<style scoped>
.dialog-footer {
  text-align: center;
}
</style>
<script>
import {
  addDataInterface,
  updateDataType,
} from "@/api/statistical";

export default {
  name: "Edit",
  props: [
    "dialogTitle", //标题
    "dialogOpen", //显示
    "dialogData",
  ],
  data() {
    return {
      sourceCodeDatas: [], //数据源编码
      formData: {},
      isMysql: false,
      // 表单校验
      rules: {
        interfaceName: [
          { required: true, message: "接口名称不能为空", trigger: "blur" },
        ],
        interfaceMulticastAddress: [
          { required: true, message: "接口地址不能为空", trigger: "blur" },
        ],
        interfacePort: [
          { required: true, message: "接口端口不能为空", trigger: "blur" },
        ],
      },
    };
  },
  watch: {},
  created() {},
  mounted() {
    this.init();
  },
  methods: {
    init() {
      this.formData = this.dialogData;
      console.log(119, "formdata:", this.formData);
    },
    // 取消按钮
    cancel() {
      this.$emit("closeDialog");
    },
    
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        console.log("submitForm", this.formData)
        if (valid) {
          if (this.formData.id != undefined) {
            console.log('update');
            updateDataType(this.formData).then((response) => {
              console.log(response);
              if (response.code == 200) {
                this.$message({ message: "操作成功", type: "success" });
                this.$emit("closeDialog");
              } else {
                this.$message({ message: response.message, type: "error" });
              }
            });
          } else {
            addDataInterface(this.formData).then((response) => {
              console.log('add', response);
              if (response.code == 200) {
                this.$message({ message: "操作成功", type: "success" });
                this.$emit("closeDialog");
              } else {
                this.$message({ message: response.message, type: "error" });
              }
            });
          }
        }
      });
    },
    
  },
};
</script>
